<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
<%  
    String path = request.getContextPath();  
    String basePath = request.getScheme() + "://"  
            + request.getServerName() + ":" + request.getServerPort()  
            + path + "/";  
%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <base href="<%=basePath%>">  
    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="cache-control" content="no-cache">  
    <meta http-equiv="expires" content="0">      
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    <meta http-equiv="description" content="This is my page">  
    <!-- 
    <link rel="stylesheet" type="text/css" href="styles.css"> 
    -->  
    <script language="javascript" src="<%=path%>/js/jquery-1.9.0.min.js" ></script>  
    <script type="text/javascript" src="<%=path%>/ajaxFileUpload/ajaxfileupload.js" ></script>  
    <script type="text/javascript">  
    function ajaxFileUpload()  
    {  
      
    $("#loading")  
        .ajaxStart(function(){  
            $(this).show();  
        })//开始上传文件时显示一个图片  
        .ajaxComplete(function(){  
            $(this).hide();  
        });//文件上传完成将图片隐藏起来  
          
       $.ajaxFileUpload({  
                 url:'<%=path%>/FileUpload',             //需要链接到服务器地址  
                 secureuri:false,  
                 fileElementId:'uploadFileInput',                         //文件选择框的id属性  
                 dataType: 'json',                                     //服务器返回的格式，可以是json  
                 success: function (data, status)             //相当于java中try语句块的用法  
                 {     
                 //alert(data);       //data是从服务器返回来的值     
                     $('#result').html('上传图片成功!请复制图片地址<br/>'+data.src);  
   
                 },  
                 error: function (data, status, e)             //相当于java中catch语句块的用法  
                 {  
                     $('#result').html('上传图片失败');  
                 }  
               }  
             );  
    }  
    </script>  
  </head>  
    
  <body>   
  <div id="result" style="FONT:12px 宋体"></div><br/>  
 <img id="loading" src="<%=path %>/ajaxFileUpload/loading.gif" style="display:none;">  
        <form name="form_uploadImg" action="" method="POST" enctype="multipart/form-data">  
 <input id="uploadFileInput" type="file" size="45" name="uploadFileInput" class="input" />  
 <input type="button" id="buttonUpload" onclick="return ajaxFileUpload();" value="上传图片"/>  
 </form>  
</html>  